package com.easy;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Lxk on 2019/5/12.
 */


public class Solution257 {

    void searchAllPath(TreeNode curNode, String path, List<String> allPath){
        if(curNode == null){
            return ;
        }
        if(curNode.left == null && curNode.right == null){
            path += curNode.val;
            allPath.add(path);
        }
        if(curNode.left == null){
            path += curNode.val + "->";
            searchAllPath(curNode.right, path, allPath);
        }
        if(curNode.right == null){
            path += curNode.val + "->";
            searchAllPath(curNode.left, path, allPath);
        }
        if(curNode.left != null && curNode.right != null){
            path += curNode.val + "->";
            searchAllPath(curNode.left, path, allPath);
            searchAllPath(curNode.right, path, allPath);
        }
    }

    public List<String> binaryTreePaths(TreeNode root) {
        List<String> allPath = new ArrayList<>();
        searchAllPath(root, "", allPath);
        return allPath;
    }

}
